 /* To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package share;

import java.io.Serializable;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author mire
 */
public class Server implements Serializable {

    protected String myIPAddress;
    protected int threadNo = 0;
    protected int centralPort = 0;
    protected boolean online = true;

    public Server(String myIPAddress) {
        this.myIPAddress = myIPAddress;
    }

    public Server(String address, int threadNo) {
        this.myIPAddress = address;
        this.threadNo = threadNo;
    }

    public Server(int threadNo) {
        this.threadNo = threadNo;
        try {
            myIPAddress = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException ex) {
            myIPAddress = null;
            Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.online = true;
    }

    public Server(int threadNo, int centralPort) {
        try {
            myIPAddress = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException ex) {
            myIPAddress = null;
            Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
        }

        this.threadNo = threadNo;
        this.centralPort = centralPort;
    }

    public Server(String myIPAddress, int threadNo, int centralPort) {
        this.myIPAddress = myIPAddress;
        this.threadNo = threadNo;
        this.centralPort = centralPort;
    }

    public int getCentralPort() {
        return centralPort;
    }

    public String getAddress() {
        return myIPAddress;
    }

    public int getThreadNo() {
        return threadNo;
    }

    public boolean isOnline() {
        return online;
    }

    public synchronized void setOnline(boolean online) {
        this.online = online;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Server other = (Server) obj;
        if ((this.myIPAddress == null) ? (other.myIPAddress != null) : !this.myIPAddress.equals(other.myIPAddress)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Server{" + "myIPAddress=" + myIPAddress + ", threadNo=" + threadNo + '}';
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + (this.myIPAddress != null ? this.myIPAddress.hashCode() : 0);
        hash = 53 * hash + this.threadNo;
        hash = 53 * hash + this.centralPort;
        return hash;
    }
}
